﻿; $(function () {


    $("#toolbar").ligerToolBar({
        items: [{
            text: '添加',
            icon: '',
            id: 'btnSave',
            click: function (parameters) {
                location.href = "/Company/Album";
            }
        },
            {
                text: '编辑',
                icon: '',
                id: 'btnEdit',
                click: function (parameters) {
                    var rows = manager.getSelectedRows();
                    if (rows && rows.length == 1) {
                        var row = manager.getSelectedRow();
                        if (row && row.AlbumId != "") {
                            //if (row.IsChecked == 1) {
                            //} else {
                            location.href = "/Company/Album?aid=" + row.AlbumId;
                            // }
                        } else {
                            $.ligerDialog.warn('请选择单个相册进行编辑');
                        }
                    } else {
                        $.ligerDialog.warn('请选择单个相册进行编辑');
                    }
                }
            },
            {
                text: '删除',
                icon: '',
                id: 'btnDelete',
                click: function (parameters) {

                    var rows = manager.getSelectedRows();
                    if (rows && rows.length > 0) {
                        if (confirm("删除相册，相册内图片将一并删除，确认删除？")) {
                            var ids = new Array();
                            $.each(rows, function () {
                                ids.push(this.AlbumId);
                            });
                            $.ajax({
                                url: '/Company/DeleteAlbums',
                                dataType: 'json',
                                type: 'post',
                                data: { ids: ids.join(",") },
                                traditional: true,
                                success: function (callback) {
                                    if (callback) {
                                        $.ligerDialog.alert('删除成功', function (yes) {
                                            manager.loadData();
                                        });
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                },
                                error: function (ex) {
                                    $.ligerDialog.error('删除失败');
                                }
                            });
                        }

                    } else {

                    }


                }
            },
            {
                text: '图片管理',
                icon: '',
                id: 'btnManage',
                click: function () {
                    var rows = manager.getSelectedRows();
                    if (rows && rows.length == 1) {
                        var row = manager.getSelectedRow();
                        if (row && row.AlbumId != "") {
                            //if (row.IsChecked == 1) {
                            //} else {
                            location.href = "/Company/Photos?aid=" + row.AlbumId;
                            // }
                        } else {
                            $.ligerDialog.warn('请选择一个相册');
                        }
                    } else {
                        $.ligerDialog.warn('请选择一个相册');
                    }
                }
            }
        ]
    });


    var manager = $("#grid").ligerGrid({
        columns: [
            {
                display: '序号',
                align: 'center',
                width: 50,
                minWidth: 50,
                render: function (item, i) {
                    return (i + 1).toString();
                }
            },
            {
                display: '相册Id',
                align: 'left',
                width: 200,
                minWidth: 100,
                name: 'AlbumId',
                hide: true
            },
            {
                display: '相册名称',
                align: 'left',
                width: 200,
                minWidth: 100,
                name: 'AlbumName'
            }
        ],
        width: '99.85%',
        height: '100%',
        heightDiff: -20,
        pageSizeOptions: [5, 10, 15, 20],
        pageSize: 15,
        alternatingRow: false,
        url: "/Company/Albums",
        headerRowHeight: 26,
        checkbox: true,
        usePager: false,
        autoCheckChildren: false,
        dataAction: "server"
    });

});